package api.action;

import api.model.*;
import api.service.ApiCollectService;
import m.common.action.ActionMeta;
import m.common.action.RequestMeta;
import m.common.action.VueResult;
import m.common.model.util.*;
import m.html.VueCollectResult;
import m.html.VueFormResult;
import m.html.VueListResult;
import m.html.collect.CollectColumn;
import m.html.element.Element;
import m.html.element.attr.Align;
import m.html.element.attr.ButtonType;
import m.html.element.other.ItemsQuery;
import m.html.element.other.Param;
import m.html.form.*;
import m.html.list.*;
import m.system.cache.CacheUtil;
import m.system.exception.MException;
import m.system.util.ArrayUtil;
import m.system.util.JSONMessage;
import m.system.util.StringUtil;
import manage.action.ManageAction;
import manage.model.AdminLogin;
import manage.util.DictionaryUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@ActionMeta(name="api/apiCollect")
public class ApiCollectAction extends ManageAction {
    private ApiCollect model;
    private ApiCollectJoin join;
    private ApiCollectColumn column;

    /**
     * 汇总页面 根据collectOid展示页面效果
     * 
     *  Exception
     */
    public VueResult toCollectPage() throws Exception {
        verifyMenu("A2102");
        verifyAdminOperPower("manage_api_power");
        AdminLogin admin=getSessionAdmin();
        String collectOid=getParamsValue("collectOid");
        ApiCollect collect= ModelQueryList.getModel(ApiCollect.class,collectOid,"*");
        FromQueryList from=toFromQueryList(collect,admin,false);
        VueCollectResult result=getVueCollectResult(collect.getTitle(), from, actionUrl("toCollectPage"));
        result.setSubTitle(StringUtil.noSpace(collect.getSubTitle()));
        result.setMergeCellsInfo(collect.getScol(), collect.getSlength());
        result.setFunction(
            ArrayUtil.isContain(collect.getFunctions(),"excel"),
            ArrayUtil.isContain(collect.getFunctions(),"chart")
        );
        if(StringUtil.noSpace(collect.getShowIndexColumn()).equals("Y")){
            result.addCol(collectIndexColumn());
        }
        List<ApiCollectColumn> cols=ModelQueryList.getModelList(ApiCollectColumn.class,new String[]{"*"},null,
            QueryCondition.eq("collect.oid",collectOid), QueryOrder.asc("sort"));
        for(ApiCollectColumn col : cols){
            result.addCol(toCollectColumn(col,admin));
        }
        return result;
    }
    private FromQueryList toFromQueryList(ApiCollect collect,AdminLogin admin,boolean addCol) throws Exception {
        List<ApiCollectJoin> joins=ModelQueryList.getModelList(ApiCollectJoin.class,new String[]{"*","collect.*"},null,
            QueryCondition.eq("apiCollect.oid",collect.getOid()), QueryOrder.asc("sort"));
        FromQueryList from;
        if("table".equals(collect.getSource())) {
            from=FromQueryList.fromGroup(collect.getAlias(), collect.getTable().getOid());
        }else{
            from=FromQueryList.fromGroup(collect.getAlias(), toFromQueryList(collect,admin,true));
        }
        for(ApiCollectJoin join : joins){
            if("table".equals(join.getSource())) {
                from.join(join.getJoinType(),TableQueryList.instance(join.getTable().getOid(),new String[]{},null,null),join.getAlias(),castSession(join.getJoinOn(),admin));
            }else{
                from.join(join.getJoinType(),toFromQueryList(join.getCollect(),admin,true),join.getAlias(),castSession(join.getJoinOn(),admin));
            }
        }
        if(!StringUtil.isSpace(collect.getSqlCondition())) from.addCondition(castSession(collect.getSqlCondition(),admin));
        if(!StringUtil.isSpace(collect.getSqlOrder())) from.addOrder(castSession(collect.getSqlOrder(),admin));
        if(!StringUtil.isSpace(collect.getSqlHaving())) from.addHaving(castSession(collect.getSqlHaving(),admin));
        List<ApiCollectColumn> cols=ModelQueryList.getModelList(ApiCollectColumn.class,new String[]{"*"},null,
            QueryCondition.eq("collect.oid",collect.getOid()), QueryOrder.asc("sort"));
        if(addCol) {
            for (ApiCollectColumn col : cols) {
                from.addField(castSession(col.getField(), admin) + " " + col.getAlias());
            }
        }
        return from;
    }
    private String castSession(String exp,AdminLogin admin){
        Pattern pattern=Pattern.compile("\\#\\{:SESSION.+?\\}");
        Matcher matcher=pattern.matcher(exp);
        while(matcher.find()){
            String str=matcher.group();
            String ns=str.substring(11,str.length()-1);
            String p=null;
            try {
                switch (ns) {
                    case "oid": p = admin.getOid(); break;
                    case "token": p = admin.getToken(); break;
                    case "group": p = admin.getAdminGroup().getOid(); break;
                    case "org": p = admin.getOrgGroup().getOid(); break;
                    case "parentOrg": p = admin.getOrgGroup().getParent().getOid(); break;
                }
            }catch(Exception ignored){}
            exp=exp.replace(str, "'"+(null==p?"":p)+"'");
        }
        return exp;
    }
    private CollectColumn toCollectColumn(ApiCollectColumn col,AdminLogin admin) throws MException {
        CollectColumn cc=new CollectColumn(col.getTitle(),castSession(col.getField(),admin)+" "+col.getAlias()).setWidth(col.getWidth());
        if(!StringUtil.isSpace(col.getGroupTitle())){
            cc.setGroupTitle(col.getGroupTitle().split(","));
        }
        cc.setNumberFormat(col.getNumberFormat())//数字格式
            .setDateFormat(col.getDateFormat())//日期格式
            .setLineClamp(col.getLineClamp())//行数
            .setFilter("Y".equals(col.getIsFilter()))//过滤
            .setDictType(col.getDict());//字典
        //排序
        if("Y".equals(col.getIsOrder())) cc.setSort(true);
        else if("A".equals(col.getIsOrder())) cc.setSort(ListSortOrder.ASC);
        else if("D".equals(col.getIsOrder())) cc.setSort(ListSortOrder.DESC);
        //统计
        if("A".equals(col.getIsCount())) cc.setCount(ListCount.SUM);
        else if("B".equals(col.getIsCount())) cc.setCount(ListCount.AVG);
        else if("C".equals(col.getIsCount())) cc.setCount(ListCount.MIN);
        else if("D".equals(col.getIsCount())) cc.setCount(ListCount.MAX);
        //对齐
        if("L".equals(col.getTextAlign())) cc.setAlign(Align.LEFT);
        else if("R".equals(col.getTextAlign())) cc.setAlign(Align.RIGHT);
        else if("C".equals(col.getTextAlign())) cc.setAlign(Align.CENTER);
        return cc;
    }
    @RequestMeta(params = {"collectOid"})
    public JSONMessage getCollectTable(String collectOid) throws Exception {
        JSONMessage result=new JSONMessage(0);
        verifyAdminOperPower("manage_api_power");
        Map<String,ApiTable> map= new HashMap<>();
        ApiCollect collect = ModelQueryList.getModel(ApiCollect.class,collectOid,"*","table.*");
        if("table".equals(collect.getSource())) {
            map.put(collect.getAlias(), collect.getTable());
        }else{
            map.put(collect.getAlias(),CacheUtil.get(ApiTable.class,collect.getCollect().getOid()));
        }
        List<ApiCollectJoin> joins=ModelQueryList.getModelList(ApiCollectJoin.class,new String[]{"*","table.*"},null,
            QueryCondition.eq("apiCollect.oid",collectOid));
        for(ApiCollectJoin join : joins){
            if("table".equals(join.getSource())){
                map.put(join.getAlias(),join.getTable());
            }else{
                map.put(join.getAlias(),CacheUtil.get(ApiTable.class,join.getCollect().getOid()));
            }
        }
        map.put(":SESSION",CacheUtil.get(ApiTable.class, ApiSession.class.getName()));
        result.push("map", map);
        return result;
    }
    @RequestMeta(params = {"tableOid"})
    public JSONMessage getTableColumn(String tableOid) throws Exception {
        JSONMessage result=new JSONMessage(0);
        verifyAdminOperPower("manage_api_power");
        ApiTable tb=CacheUtil.get(ApiTable.class,tableOid);
        List<ApiColumn> list = CacheUtil.getList(ApiColumn.class,tb.getSource().equals("Y")?tb.getSourceClass():tb.getOid());
        result.push("list", list);
        return result;
    }
    public JSONMessage doSave() throws Exception {
        systemLog("模型","保存汇总模型信息");
        verifyAdminOperPower("manage_api_power");
        String msg=getService(ApiCollectService.class).save(model);
        return new JSONMessage(0,msg)
                .push("model", model);
    }
    public VueResult toEdit() throws Exception {
        verifyMenu("A2102");
        verifyAdminOperPower("manage_api_power");
        if(null!=model&&!StringUtil.isSpace(model.getOid())){
            model= ModelQueryList.getModel(model,"*","table.*");
        }else {
            model=new ApiCollect();
            model.setAlias("a");
            model.setSource("table");
            model.setScol(0);
            model.setSlength(0);
        }
        ModelForm form = new ModelForm("汇总模型");
        form.addItem(
            FormInput.input("描述", "model.description").setPlaceholder("请输入描述").setSpan(2).setRequired(true),
            FormInput.checkBoxGroup("功能", "model.functions", "api.model.ApiCollect!functions"),
            FormInput.input("标题", "model.title").setPlaceholder("请输入标题").setRequired(true),
            FormInput.input("子标题", "model.subTitle").setPlaceholder("请输入子标题").setSpan(2),
            FormInput.radio("来源", "model.source","api.model.ApiCollect!source"),
            FormTest.test("model.source=='table'",FormInput.selectItem("数据表","model.table.oid",actionUrl(ApiTableAction.class,"getApiTablesOptions")).setPlaceholder("请选择数据表").setRequired(true)),
            FormTest.test("model.source=='collect'",FormInput.selectItem("汇总表","model.collect.oid",actionUrl("getApiCollectOptions")).setPlaceholder("请选择汇总表").setRequired(true)),
            FormInput.input("表别名", "model.alias").setPlaceholder("请输入表别名"),
            FormInput.selectJsPage("SQL条件", "model","sqlCondition","'page/base/api/inputTestField.js?value='+model.sqlCondition+'&collectOid='+model.oid+'&temps[]=#{字段}'",
                    800,"{{model.sqlCondition}}").setSpan(2),
            FormInput.radio("序号列", "model.showIndexColumn","api.model.ApiCollect!showIndexColumn"),
            FormInput.selectJsPage("SQL排序", "model","sqlOrder","'page/base/api/inputTestField.js?value='+model.sqlOrder+'&collectOid='+model.oid+'&temps[]=#{字段}'",
                    800,"{{model.sqlOrder}}").setSpan(2),
            FormInput.number("合并开始列", "model.scol").setPlaceholder("请输入合并开始列"),
            FormInput.selectJsPage("聚合条件", "model","sqlHaving","'page/base/api/inputTestField.js?value='+model.sqlHaving+'&collectOid='+model.oid+'&temps[]=#{字段}'",
                    800,"{{model.sqlHaving}}").setSpan(2),
            FormInput.number("合并列长度", "model.slength").setPlaceholder("请输入合并列长度")
        )
        .addData("model",model)
        .addButton(
            FormButton.pri("保存","doSave")
        )
        .addMethod(
            FormEvent.backFlag,
            FormEvent.doJson("doSave",actionUrl("doSave"),"{model:this.model}")
                    .fillData("model").after("loadCollectJoinPage","loadCollectColumnPage")
        );
        LoadPage joinPage=new LoadPage("loadCollectJoinPage",
            actionUrl("apiCollectJoin"),"{params:{collectOid:this.model.oid}}")
            .setMounted("this.loadCollectJoinPage();");
        LoadPage columnPage=new LoadPage("loadCollectColumnPage",
            actionUrl("apiCollectColumn"),"{params:{collectOid:this.model.oid}}")
            .setMounted("this.loadCollectColumnPage();");
        VueFormResult result=new VueFormResult();
        return result.addForm(form).addForm(joinPage).addForm(columnPage);
    }
    public JSONMessage doSaveJoin() throws Exception {
        systemLog("模型","保存汇总模型表链接信息");
        verifyAdminOperPower("manage_api_power");
        String msg=getService(ApiCollectService.class).saveJoin(join);
        return new JSONMessage(0,msg)
            .push("model", join);
    }
    public JSONMessage doDelJoin() throws Exception {
        systemLog("模型","删除汇总模型表链接信息");
        verifyAdminOperPower("manage_api_power");
        ModelUpdateUtil.deleteModel(join);
        return new JSONMessage(0,"删除成功");
    }
    public JSONMessage getApiCollectOptions() throws Exception {
        return DictionaryUtil.toDictData(
            new ItemsQuery(ApiCollect.class,"description","oid")
                .setTitleExpression("concat('汇总表 - ',ifnull(#{description},''))")
                .toItems()
        );
    }
    public VueResult toEditJoin() throws Exception {
        verifyMenu("A2102");
        verifyAdminOperPower("manage_api_power");
        if(null!=join&&!StringUtil.isSpace(join.getOid())){
            join= ModelQueryList.getModel(join,"*","table.*");
        }else if(null!=join&&null!=join.getApiCollect()&&!StringUtil.isSpace(join.getApiCollect().getOid())){
            join.setJoinType("left join");
            join.setSource("table");
            join.setSort(ModelQueryList.getModelList(ApiCollectJoin.class,new String[]{"oid"},null,
                QueryCondition.eq("apiCollect.oid",join.getApiCollect().getOid())).size()+1);
            join.setAlias("a"+join.getSort());
        }else{
            throw new MException(this.getClass(),"参数错误");
        }
        ModelForm form = new ModelForm("汇总表链接");
        form.addItem(
            FormInput.number("排序", "model.sort").setPlaceholder("请输入排序"),
            FormInput.radio("链接类型", "model.joinType", "api.model.ApiCollectJoin!joinType").setSpan(2).setRequired(true),
            FormInput.input("表别名", "model.alias").setPlaceholder("请输入表别名").setRequired(true),
            FormInput.radio("来源", "model.source", "api.model.ApiCollectJoin!source").setSpan(2).setRequired(true),
            FormTest.test("model.source=='table'",FormInput.selectItem("数据表","model.table.oid",actionUrl(ApiTableAction.class,"getApiTablesOptions")).setPlaceholder("请选择数据表").setSpan(3).setRequired(true)),
            FormTest.test("model.source=='collect'",FormInput.selectItem("汇总表","model.collect.oid",actionUrl("getApiCollectOptions")).setPlaceholder("请选择汇总表").setSpan(3).setRequired(true)),
            FormElement.add(Element.tag("a-alert").A("message","保存后再设置链接条件，字段参数可选择链接表。")),
            FormInput.selectJsPage("链接条件", "model","joinOn","'page/base/api/inputTestField.js?value='+model.joinOn+'&collectOid='+model.apiCollect.oid+'&temps[]=#{字段}=#{字段},#{字段}=#{字段} and #{字段}=#{字段},#{字段}=#{字段} or #{字段}=#{字段}'",
                    800,"{{model.joinOn}}").setSpan(3)
        )
        .addData("model",join)
        .addButton(
            FormButton.pri("保存","doSave")
        )
        .addMethod(
            FormEvent.backFlag,
            FormEvent.verify("verifyModel",
                FormJsTest.test("this.model.source=='table'",FormJsTest.falseRemind("this.model.table.oid","请选择数据表")),
                FormJsTest.test("this.model.source=='collect'",FormJsTest.falseRemind("this.model.collect.oid","请选择汇总表"))
            ),
            FormEvent.doJson("doSave",actionUrl("doSaveJoin"),"{join:this.model}")
                    .before("verifyModel").fillData("model")
        );
        VueFormResult result=new VueFormResult();
        return result.addForm(form);
    }
    public JSONMessage doSaveColumn() throws Exception {
        systemLog("模型","保存汇总模型列信息");
        verifyAdminOperPower("manage_api_power");
        String msg=getService(ApiCollectService.class).saveColumn(column);
        return new JSONMessage(0,msg)
                .push("model", column);
    }
    public JSONMessage doDelColumn() throws Exception {
        systemLog("模型","删除汇总模型列信息");
        verifyAdminOperPower("manage_api_power");
        ModelUpdateUtil.deleteModel(column);
        return new JSONMessage(0,"删除成功");
    }
    public VueResult toEditColumn() throws Exception {
        verifyMenu("A2102");
        verifyAdminOperPower("manage_api_power");
        if(null!=column&&!StringUtil.isSpace(column.getOid())){
            column= ModelQueryList.getModel(column,"*","table.*");
        }else if(null!=column&&null!=column.getCollect()&&!StringUtil.isSpace(column.getCollect().getOid())){
            column.setWidth(100);
            column.setSort(ModelQueryList.getModelList(ApiCollectColumn.class,new String[]{"oid"},null,
                QueryCondition.eq("collect.oid",column.getCollect().getOid())).size()+1);
            column.setAlias("f"+column.getSort());
            column.setType("STRING");
            column.setLineClamp(2);
            column.setIsOrder("N");
            column.setIsCount("N");
            column.setIsFilter("N");
            column.setTextAlign("L");
        }else{
            throw new MException(this.getClass(),"参数错误");
        }
        ModelForm form = new ModelForm("汇总表列");
        form.addItem(
            FormInput.number("排序", "model.sort").setPlaceholder("请输入排序"),
            FormInput.input("标题", "model.title").setPlaceholder("请输入标题"),
            FormInput.input("标题组", "model.groupTitle").setPlaceholder("请输入标题组").setDescription("可以为空, 多个用英文逗号分割"),
            FormInput.input("别名", "model.alias").setPlaceholder("请输入别名").setDescription("只能输入小写字母数字和下划线"),
            FormInput.selectJsPage("字段", "model","field","'page/base/api/inputTestField.js?value='+model.field+'&collectOid='+model.collect.oid+'&temps[]=#{字段},DATE(#{字段}),SUM(#{字段}),SUM(case when #{字段}=#{字段} then #{字段} else 0 end)'",
                800,"{{model.field}}").setSpan(2),
            FormInput.radio("类型", "model.type", "api.model.ApiCollectColumn!type").setSpan(2),
            FormInput.number("列宽", "model.width").setPlaceholder("请输入列宽"),
            FormTest.test("model.type=='NUMBER'",
                FormInput.input("数字格式", "model.numberFormat").setPlaceholder("请输入数字格式"),
                FormInput.radio("汇总", "model.isCount", "api.model.ApiCollectColumn!isCount").setSpan(2).setPlaceholder("请选择汇总")
            ),
            FormTest.test("model.type=='DATE'",FormInput.input("日期格式", "model.dateFormat").setPlaceholder("请输入日期格式")),
            FormTest.test("model.type=='STRING'",FormInput.number("最大行显", "model.lineClamp").setPlaceholder("请输入最大行显")),
            FormTest.test("model.type=='DATE'||model.type=='STRING'",FormInput.select("列排序", "model.isOrder", "api.model.ApiCollectColumn!isOrder").setPlaceholder("请选择排序")),
            FormInput.select("对齐", "model.textAlign", "api.model.ApiCollectColumn!textAlign").setPlaceholder("请选择对齐"),
            FormTest.test("model.type!='NUMBER'||model.isCount=='N'",FormInput.select("过滤", "model.isFilter", "api.model.ApiCollectColumn!isFilter").setPlaceholder("请选择过滤")),
            FormTest.test("model.type=='STRING'",FormInput.input("字典", "model.dict").setSpan(2).setPlaceholder("请输入字典"))
        )
        .addData("model",column)
        .addButton(
            FormButton.pri("保存","doSave")
        )
        .addMethod(
            FormEvent.backFlag,
            FormEvent.doJson("doSave",actionUrl("doSaveColumn"),"{column:this.model}")
                .success("backFlag")
        );
        VueFormResult result=new VueFormResult();
        return result.addForm(form);
    }
    public VueResult apiCollectList() throws Exception{
        verifyMenu("A2102");
        boolean power=hasAdminOperPower("manage_api_power");
        VueListResult result=getVueListResult("汇总表列表", ApiCollect.class,actionUrl("apiCollectList"));
        result.setSubTitle("添加或者编辑汇总表信息。");
        result.addCol(toIndexColumn());
        result.addCol(toTextColumn("描述", "description",200,true));
        result.addCol(toTextColumn("标题", "title",true));
        result.addCol(toTextColumn("子标题", "subTitle",200,true));
        result.addCol(toHtmlColumn("开始查询", 150,"{{record[record.source].description}}"));
        result.addQueryFields("table.description","collect.description","source");
        if(power) result.addCol(toSpaceColumn("操作",150,
            ListButton.page("修改", ButtonType.PRIMARY,actionUrl("toEdit"), SuccessMethod.REFRESH)
                .addParam("model.oid","oid"),
            ListButton.page("查询", ButtonType.SUCCESS,actionUrl("toCollectPage"))
                .addParam("params[collectOid]","oid")
        ).setFixed(Align.RIGHT));
        if(power) result.addButton(
            ListButton.page("新增",ButtonType.PRIMARY,actionUrl("toEdit"),SuccessMethod.REFRESH)
        );
        return result;
    }
    public VueResult apiCollectJoin() throws Exception{
        verifyMenu("A2102");
        boolean power=hasAdminOperPower("manage_api_power");
        String collectOid=getParamsValue("collectOid");
        VueListResult result=getVueListResult("汇总表", ApiCollectJoin.class,actionUrl("apiCollectJoin"));
        result.setSubTitle("链接");
        //result.addCol(toIndexColumn());
        result.addCol(toIntegerColumn("排序", "sort",60).setCount(ListCount.NONE).setSort(ListSortOrder.ASC));
        result.addCol(toTextColumn("链接类型", "joinType",true));
        result.addCol(toTextColumn("来源","source",true).setDictOption(ApiCollectJoin.class,"source"));
        result.addCol(toTextColumn("链接表", "table.description",true)
            .setFieldExpression("case when #{source}='table' then concat(ifnull(#{table.description},''),#{table.name}) else concat('汇总表',ifnull(#{collect.description},'')) end"));
        result.addCol(toTextColumn("别名", "alias",true));
        result.addCol(toTextColumn("链接条件", "joinOn",200,true));
        if(power) result.addCol(toSpaceColumn("操作",125,
            ListButton.modal("修改", ButtonType.PRIMARY,actionUrl("toEditJoin"),900, SuccessMethod.REFRESH)
                .addParam("join.oid","oid"),
            ListButton.ajax("删除", ButtonType.ERROR,actionUrl("doDelJoin"), SuccessMethod.REFRESH)
                .addParam("join.oid","oid").setConfirm("确定要删除吗？")
        ).setFixed(Align.RIGHT));
        if(power&&StringUtil.notSpace(collectOid)) result.addButton(
            ListButton.modal("新增",ButtonType.PRIMARY,actionUrl("toEditJoin"),900,SuccessMethod.REFRESH)
                .addQueryParam(Param.value("join.apiCollect.oid",collectOid))
        );
        result.addCondition(QueryCondition.eq("apiCollect.oid",collectOid));
        return result;
    }
    public VueResult apiCollectColumn() throws Exception{
        verifyMenu("A2102");
        boolean power=hasAdminOperPower("manage_api_power");
        String collectOid=getParamsValue("collectOid");
        VueListResult result=getVueListResult("汇总表", ApiCollectColumn.class,actionUrl("apiCollectColumn"));
        result.setSubTitle("列");
        //result.addCol(toIndexColumn());
        result.addCol(toIntegerColumn("排序", "sort",60).setCount(ListCount.NONE).setSort(ListSortOrder.ASC));
        result.addCol(toTextColumn("标题", "title",true));
        result.addCol(toTextColumn("标题组", "groupTitle",true));
        result.addCol(toTextColumn("字段", "field",250,true));
        result.addCol(toTextColumn("别名", "alias",true));
        result.addCol(toIntegerColumn("宽", "width",60,true));
        result.addCol(toTextColumn("类型","type",true).setDictOption(ApiCollectColumn.class,"type"));
        result.addCol(toTextColumn("排序","isOrder",true).setDictOption(ApiCollectColumn.class,"isOrder"));
        result.addCol(toTextColumn("汇总","isCount",true).setDictOption(ApiCollectColumn.class,"isCount"));
        result.addCol(toTextColumn("过滤","isFilter",true).setDictOption(ApiCollectColumn.class,"isFilter"));
        result.addCol(toTextColumn("对齐","textAlign",true).setDictOption(ApiCollectColumn.class,"textAlign"));
        if(power) result.addCol(toSpaceColumn("操作",125,
            ListButton.modal("修改", ButtonType.PRIMARY,actionUrl("toEditColumn"),1050, SuccessMethod.REFRESH)
                .addParam("column.oid","oid"),
            ListButton.ajax("删除", ButtonType.ERROR,actionUrl("doDelColumn"), SuccessMethod.REFRESH)
                .addParam("column.oid","oid").setConfirm("确定要删除吗？")
        ).setFixed(Align.RIGHT));
        if(power&&StringUtil.notSpace(collectOid)) result.addButton(
            ListButton.modal("新增",ButtonType.PRIMARY,actionUrl("toEditColumn"),1050,SuccessMethod.REFRESH)
                .addQueryParam(Param.value("column.collect.oid",collectOid))
        );
        result.addCondition(QueryCondition.eq("collect.oid",collectOid));
        return result;
    }
    public ApiCollect getModel() {
        return model;
    }


    public void setModel(ApiCollect model) {
        this.model = model;
    }

    public ApiCollectJoin getJoin() {
        return join;
    }

    public void setJoin(ApiCollectJoin join) {
        this.join = join;
    }

    public ApiCollectColumn getColumn() {
        return column;
    }

    public void setColumn(ApiCollectColumn column) {
        this.column = column;
    }
}
